from pytex import MathDocument
from pytex.utils import md2tex, pseudocode
import os
from pylatex import NoEscapeStr

base_packages = ["amsmath", "graphicx", "amssymb"]
md2tex_packages = ["cite", "hyperref", "listings", "algorithm", "algpseudocode", "algorithmicx"]
doc = MathDocument('数学建模', packages=base_packages + md2tex_packages, standard="GJS", preface=False)
doc.set_information()

doc.add_title()
doc.body_append(NoEscapeStr(r"\lstset{numbers=left,numberstyle=\tiny,keywordstyle=\color{blue!70},"
                            r"commentstyle=\color{red!50!green!50!blue!50},frame=shadowbox,"
                            r"rulesepcolor=\color{red!20!green!20!blue!20}}"))
doc.add_abstract(md2tex("./md/abstract.md"))
doc.add_toc()
doc.add_section(path="./md/问题重述.md")  # 问题重述
doc.add_section(path="./md/问题分析.md")  # 问题分析
doc.add_section(path="./md/模型假设.md")  # 模型假设
doc.add_section(title="符号说明", content=doc.var_table)  # 添加变量表
doc.add_section(path="./md/模型的建立与求解.md")  # 模型的建立与求解
doc.add_section(path="./md/模型的评价.md")  # 模型的评价
doc.add_section(path="./md/模型的改进与推广.md")  # 模型的改进与推广
doc.add_bib("references")
doc.add_page()
doc.body_append(r"\appendix")
doc.add_section(r"\appendix")

print("正在生成pdf")

path = "../resources"
if not os.path.exists(path):
    os.mkdir(path)
doc.generate_pdf(path + '/math', compiler='XeLatex', clean_tex=False, clean=False)

print("md注释, lis改成arr")
print("md端img添加路径斜杠")
print("md端伪代码else bug")
print("md端表格")
